import {request} from "vendor/utils/T";
import { toApi } from "@/service/proxyApi";
import {postJSON, put, del} from "vendor/utils/T/core/request";

import {RespDataType, RequestDataType} from "./apiType";

export * from "./apiType";
const {get} = request;

/**
 * 获取角色分页列表数据
 */
export const getRolePageList = (params: { page: number; pageSize: number; roleName?: string }) => {
    return get<RespDataType.RolePageList>(toApi("/system/role/list"),params);
}

/**
 * 创建角色
 */
export const createRole = (params: RequestDataType.CreateRoleItem) => {
    return postJSON(toApi("/system/role"), params);
}

/**
 * 更新角色
 */
export const updateRole = (roleId: number, params: RequestDataType.UpdateRoleItem) => {
    params.roleId = roleId;
    return put(toApi("/system/role"), params);
}

/**
 * 删除角色
 */
export const delRole = (roleIdList: number[]) => {
    return del(toApi("/system/role/" + roleIdList.toString()));
}

/**
 * 获取单个角色内容
 */
export const getRole = (roleId: number) => {
    return get(toApi("/system/role/"+roleId));
}

/**
 * 获取菜单树形数据
 */
export const getMenuTree = () => {
    return get<RespDataType.MenuTree>(toApi("system/menu/treeselect"), {status: "0"});
}

/**
 * 获取角色已有的权限菜单
 */
export const getRoleSelectedMenuIds = (roleId: number) => {
    return get<RespDataType.RoleMenuTreeItem>(toApi("system/menu/roleMenuTreeselect/" + roleId));
};

/**
 * 更新数据权限
 */
export const updateRoleDataScope = (roleId: number, params: { roleId?: number, dataScope: string, deptIds?: number[] }) => {
    params.roleId = roleId;
    return put(toApi("/system/role/dataScope"), params);
}

/**
 * 获取角色的自定义数据范围
 */
export const getRoleDeptCustomDataScope = (roleId: number) => {
    return get<RespDataType.RoleSelectedCustomDataScope>(toApi("/system/dept/roleDeptTreeselect/"+roleId));
}

